package ejb.manager;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import ejb.dao.RoleDAO;
import ejb.dao.UserDAO;
import ejb.entity.DefaultRole;
import ejb.entity.User;
import ejb.entity.Role;
@Stateless
public class DefaultRoleManager implements RoleManager {
	@EJB
	UserDAO userdao;
	@EJB
	RoleDAO roledao;
	
	
	/* (non-Javadoc)
	 * @see ejb.manager.RoleManager#activation(java.lang.String)
	 */
	@Override
	public boolean activation(String code){
		User u = userdao.getUserByCode(code);
		if(u != null){
			u.setActive((byte)1);
			u.setCode(null);
			Role r = new DefaultRole(u.getUserName(), "user");
			r = roledao.create(r);			
			return true;
		}else return false;
	}
}
